Namespacing everything to /UVa.
[andmenj-acm.git] / UVa / 10041 - Vito's Family / 10041.cpp
blobf74981a78f4e32905dabd3c6f9cf8e3b9eb3f06d
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <iostream>
5 using namespace std;
7 int compara(const void* i, const void* j){
8 if (*(int*)i == *(int*)j) return (0);
9 if (*(int*)i == 0) return (1);
10 if (*(int*)j == 0) return (-1);
11 if (*(int*)i > *(int*)j) return (1);
12 if (*(int*)i < *(int*)j) return (-1);
16 int main(int argc, char *argv[])
18 int cases, r, s[500], median, sum;
19 //scanf("%d", &cases);
20 cin >> cases;
21 for (int contadorCases=0; contadorCases < cases; contadorCases++){
22 //scanf("%d", &r);
23 cin >> r;
24 for (int i = 0; i < r; i++){
25 //scanf("%d", &s[i]);
26 cin >> s[i];
28 qsort(s, r, sizeof(int), compara);
29 median = s[r/2];
30 sum = 0;
31 for (int i = 0; i < r; i++){
32 sum += abs(s[i] - median);
34 //printf("%d\n", sum);
35 cout << sum << endl;
38 return 0;